<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><link href="http://search.cpan.org/s/style.css" rel="stylesheet" type="text/css">
<title>GeodSolve(1)</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>

<body>



<h1 id="NAME">NAME</h1>

<p>GeodSolve -- perform geodesic calculations</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<p><b>GeodSolve</b> [ <b>-i</b> | <b>-L</b> <i>lat1</i> <i>lon1</i> <i>azi1</i> | <b>-D</b> <i>lat1</i> <i>lon1</i> <i>azi1</i> <i>s13</i> | <b>-I</b> <i>lat1</i> <i>lon1</i> <i>lat3</i> <i>lon3</i> ] [ <b>-a</b> ] [ <b>-e</b> <i>a</i> <i>f</i> ] [ <b>-u</b> ] [ <b>-F</b> ] [ <b>-d</b> | <b>-:</b> ] [ <b>-w</b> ] [ <b>-b</b> ] [ <b>-f</b> ] [ <b>-p</b> <i>prec</i> ] [ <b>-E</b> ] [ <b>--comment-delimiter</b> <i>commentdelim</i> ] [ <b>--version</b> | <b>-h</b> | <b>--help</b> ] [ <b>--input-file</b> <i>infile</i> | <b>--input-string</b> <i>instring</i> ] [ <b>--line-separator</b> <i>linesep</i> ] [ <b>--output-file</b> <i>outfile</i> ]</p>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>The shortest path between two points on the ellipsoid at (<i>lat1</i>, <i>lon1</i>) and (<i>lat2</i>, <i>lon2</i>) is called the geodesic. Its length is <i>s12</i> and the geodesic from point 1 to point 2 has forward azimuths <i>azi1</i> and <i>azi2</i> at the two end points.</p>

<p><b>GeodSolve</b> operates in one of three modes:</p>

<ol>

<li><p>By default, <b>GeodSolve</b> accepts lines on the standard input containing <i>lat1</i> <i>lon1</i> <i>azi1</i> <i>s12</i> and prints <i>lat2</i> <i>lon2</i> <i>azi2</i> on standard output. This is the direct geodesic calculation.</p>

</li>
<li><p>With the <b>-i</b> command line argument, <b>GeodSolve</b> performs the inverse geodesic calculation. It reads lines containing <i>lat1</i> <i>lon1</i> <i>lat2</i> <i>lon2</i> and prints the corresponding values of <i>azi1</i> <i>azi2</i> <i>s12</i>.</p>

</li>
<li><p>Command line arguments <b>-L</b> <i>lat1</i> <i>lon1</i> <i>azi1</i> specify a geodesic line. <b>GeodSolve</b> then accepts a sequence of <i>s12</i> values (one per line) on standard input and prints <i>lat2</i> <i>lon2</i> <i>azi2</i> for each. This generates a sequence of points on a single geodesic. Command line arguments <b>-D</b> and <b>-I</b> work similarly with the geodesic line defined in terms of a direct or inverse geodesic calculation, respectively.</p>

</li>
</ol>

<h1 id="OPTIONS">OPTIONS</h1>

<dl>

<dt id="i"><b>-i</b></dt>
<dd>

<p>perform an inverse geodesic calculation (see 2 above).</p>

</dd>
<dt id="L-lat1-lon1-azi1"><b>-L</b> <i>lat1</i> <i>lon1</i> <i>azi1</i></dt>
<dd>

<p>line mode (see 3 above); generate a sequence of points along the geodesic specified by <i>lat1</i> <i>lon1</i> <i>azi1</i>. The <b>-w</b> flag can be used to swap the default order of the 2 geographic coordinates, provided that it appears before <b>-L</b>. (<b>-l</b> is an alternative, deprecated, spelling of this flag.)</p>

</dd>
<dt id="D-lat1-lon1-azi1-s13"><b>-D</b> <i>lat1</i> <i>lon1</i> <i>azi1</i> <i>s13</i></dt>
<dd>

<p>line mode (see 3 above); generate a sequence of points along the geodesic specified by <i>lat1</i> <i>lon1</i> <i>azi1</i> <i>s13</i>. The <b>-w</b> flag can be used to swap the default order of the 2 geographic coordinates, provided that it appears before <b>-D</b>. Similarly, the <b>-a</b> flag can be used to change the interpretation of <i>s13</i> to <i>a13</i>, provided that it appears before <b>-D</b>.</p>

</dd>
<dt id="I-lat1-lon1-lat3-lon3"><b>-I</b> <i>lat1</i> <i>lon1</i> <i>lat3</i> <i>lon3</i></dt>
<dd>

<p>line mode (see 3 above); generate a sequence of points along the geodesic specified by <i>lat1</i> <i>lon1</i> <i>lat3</i> <i>lon3</i>. The <b>-w</b> flag can be used to swap the default order of the 2 geographic coordinates, provided that it appears before <b>-I</b>.</p>

</dd>
<dt id="a"><b>-a</b></dt>
<dd>

<p>toggle the arc mode flag (it starts off); if this flag is on, then on input <i>and</i> output <i>s12</i> is replaced by <i>a12</i> the arc length (in degrees) on the auxiliary sphere. See <a href="#AUXILIARY-SPHERE">&quot;AUXILIARY SPHERE&quot;</a>.</p>

</dd>
<dt id="e-a-f"><b>-e</b> <i>a</i> <i>f</i></dt>
<dd>

<p>specify the ellipsoid via the equatorial radius, <i>a</i> and the flattening, <i>f</i>. Setting <i>f</i> = 0 results in a sphere. Specify <i>f</i> &lt; 0 for a prolate ellipsoid. A simple fraction, e.g., 1/297, is allowed for <i>f</i>. By default, the WGS84 ellipsoid is used, <i>a</i> = 6378137 m, <i>f</i> = 1/298.257223563.</p>

</dd>
<dt id="u"><b>-u</b></dt>
<dd>

<p>unroll the longitude. Normally, on output longitudes are reduced to lie in [-180deg,180deg). However with this option, the returned longitude <i>lon2</i> is &quot;unrolled&quot; so that <i>lon2</i> - <i>lon1</i> indicates how often and in what sense the geodesic has encircled the earth. Use the <b>-f</b> option, to get both longitudes printed.</p>

</dd>
<dt id="F"><b>-F</b></dt>
<dd>

<p>fractional mode. This only has any effect with the <b>-D</b> and <b>-I</b> options (and is otherwise ignored). The values read on standard input are interpreted as fractional distances to point 3, i.e., as <i>s12</i>/<i>s13</i> instead of <i>s12</i>. If arc mode is in effect, then the values denote fractional arc length, i.e., <i>a12</i>/<i>a13</i>.</p>

</dd>
<dt id="d"><b>-d</b></dt>
<dd>

<p>output angles as degrees, minutes, seconds instead of decimal degrees.</p>

</dd>
<dt id="pod"><b>-:</b></dt>
<dd>

<p>like <b>-d</b>, except use : as a separator instead of the d, &#39;, and &quot; delimiters.</p>

</dd>
<dt id="w"><b>-w</b></dt>
<dd>

<p>toggle the longitude first flag (it starts off); if the flag is on, then on input and output, longitude precedes latitude (except that, on input, this can be overridden by a hemisphere designator, <i>N</i>, <i>S</i>, <i>E</i>, <i>W</i>).</p>

</dd>
<dt id="b"><b>-b</b></dt>
<dd>

<p>report the <i>back</i> azimuth at point 2 instead of the forward azimuth.</p>

</dd>
<dt id="f"><b>-f</b></dt>
<dd>

<p>full output; each line of output consists of 12 quantities: <i>lat1</i> <i>lon1</i> <i>azi1</i> <i>lat2</i> <i>lon2</i> <i>azi2</i> <i>s12</i> <i>a12</i> <i>m12</i> <i>M12</i> <i>M21</i> <i>S12</i>. <i>a12</i> is described in <a href="#AUXILIARY-SPHERE">&quot;AUXILIARY SPHERE&quot;</a>. The four quantities <i>m12</i>, <i>M12</i>, <i>M21</i>, and <i>S12</i> are described in <a href="#ADDITIONAL-QUANTITIES">&quot;ADDITIONAL QUANTITIES&quot;</a>.</p>

</dd>
<dt id="p-prec"><b>-p</b> <i>prec</i></dt>
<dd>

<p>set the output precision to <i>prec</i> (default 3); <i>prec</i> is the precision relative to 1 m. See <a href="#PRECISION">&quot;PRECISION&quot;</a>.</p>

</dd>
<dt id="E"><b>-E</b></dt>
<dd>

<p>use &quot;exact&quot; algorithms (based on elliptic integrals) for the geodesic calculations. These are more accurate than the (default) series expansions for |<i>f</i>| &gt; 0.02.</p>

</dd>
<dt id="comment-delimiter-commentdelim"><b>--comment-delimiter</b> <i>commentdelim</i></dt>
<dd>

<p>set the comment delimiter to <i>commentdelim</i> (e.g., &quot;#&quot; or &quot;//&quot;). If set, the input lines will be scanned for this delimiter and, if found, the delimiter and the rest of the line will be removed prior to processing and subsequently appended to the output line (separated by a space).</p>

</dd>
<dt id="version"><b>--version</b></dt>
<dd>

<p>print version and exit.</p>

</dd>
<dt id="h"><b>-h</b></dt>
<dd>

<p>print usage and exit.</p>

</dd>
<dt id="help"><b>--help</b></dt>
<dd>

<p>print full documentation and exit.</p>

</dd>
<dt id="input-file-infile"><b>--input-file</b> <i>infile</i></dt>
<dd>

<p>read input from the file <i>infile</i> instead of from standard input; a file name of &quot;-&quot; stands for standard input.</p>

</dd>
<dt id="input-string-instring"><b>--input-string</b> <i>instring</i></dt>
<dd>

<p>read input from the string <i>instring</i> instead of from standard input. All occurrences of the line separator character (default is a semicolon) in <i>instring</i> are converted to newlines before the reading begins.</p>

</dd>
<dt id="line-separator-linesep"><b>--line-separator</b> <i>linesep</i></dt>
<dd>

<p>set the line separator character to <i>linesep</i>. By default this is a semicolon.</p>

</dd>
<dt id="output-file-outfile"><b>--output-file</b> <i>outfile</i></dt>
<dd>

<p>write output to the file <i>outfile</i> instead of to standard output; a file name of &quot;-&quot; stands for standard output.</p>

</dd>
</dl>

<h1 id="INPUT">INPUT</h1>

<p><b>GeodSolve</b> measures all angles in degrees and all lengths (<i>s12</i>) in meters, and all areas (<i>S12</i>) in meters^2. On input angles (latitude, longitude, azimuth, arc length) can be as decimal degrees or degrees, minutes, seconds. For example, <code>40d30</code>, <code>40d30&#39;</code>, <code>40:30</code>, <code>40.5d</code>, and <code>40.5</code> are all equivalent. By default, latitude precedes longitude for each point (the <b>-w</b> flag switches this convention); however on input either may be given first by appending (or prepending) <i>N</i> or <i>S</i> to the latitude and <i>E</i> or <i>W</i> to the longitude. Azimuths are measured clockwise from north; however this may be overridden with <i>E</i> or <i>W</i>.</p>

<p>For details on the allowed formats for angles, see the <code>GEOGRAPHIC COORDINATES</code> section of GeoConvert(1).</p>

<h1 id="AUXILIARY-SPHERE">AUXILIARY SPHERE</h1>

<p>Geodesics on the ellipsoid can be transferred to the <i>auxiliary sphere</i> on which the distance is measured in terms of the arc length <i>a12</i> (measured in degrees) instead of <i>s12</i>. In terms of <i>a12</i>, 180 degrees is the distance from one equator crossing to the next or from the minimum latitude to the maximum latitude. Geodesics with <i>a12</i> &gt; 180 degrees do not correspond to shortest paths. With the <b>-a</b> flag, <i>s12</i> (on both input and output) is replaced by <i>a12</i>. The <b>-a</b> flag does <i>not</i> affect the full output given by the <b>-f</b> flag (which always includes both <i>s12</i> and <i>a12</i>).</p>

<h1 id="ADDITIONAL-QUANTITIES">ADDITIONAL QUANTITIES</h1>

<p>The <b>-f</b> flag reports four additional quantities.</p>

<p>The reduced length of the geodesic, <i>m12</i>, is defined such that if the initial azimuth is perturbed by d<i>azi1</i> (radians) then the second point is displaced by <i>m12</i> d<i>azi1</i> in the direction perpendicular to the geodesic. <i>m12</i> is given in meters. On a curved surface the reduced length obeys a symmetry relation, <i>m12</i> + <i>m21</i> = 0. On a flat surface, we have <i>m12</i> = <i>s12</i>.</p>

<p><i>M12</i> and <i>M21</i> are geodesic scales. If two geodesics are parallel at point 1 and separated by a small distance <i>dt</i>, then they are separated by a distance <i>M12</i> <i>dt</i> at point 2. <i>M21</i> is defined similarly (with the geodesics being parallel to one another at point 2). <i>M12</i> and <i>M21</i> are dimensionless quantities. On a flat surface, we have <i>M12</i> = <i>M21</i> = 1.</p>

<p>If points 1, 2, and 3 lie on a single geodesic, then the following addition rules hold:</p>

<pre><code>   s13 = s12 + s23,
   a13 = a12 + a23,
   S13 = S12 + S23,
   m13 = m12 M23 + m23 M21,
   M13 = M12 M23 - (1 - M12 M21) m23 / m12,
   M31 = M32 M21 - (1 - M23 M32) m12 / m23.</code></pre>

<p>Finally, <i>S12</i> is the area between the geodesic from point 1 to point 2 and the equator; i.e., it is the area, measured counter-clockwise, of the geodesic quadrilateral with corners (<i>lat1</i>,<i>lon1</i>), (0,<i>lon1</i>), (0,<i>lon2</i>), and (<i>lat2</i>,<i>lon2</i>). It is given in meters^2.</p>

<h1 id="PRECISION">PRECISION</h1>

<p><i>prec</i> gives precision of the output with <i>prec</i> = 0 giving 1 m precision, <i>prec</i> = 3 giving 1 mm precision, etc. <i>prec</i> is the number of digits after the decimal point for lengths. For decimal degrees, the number of digits after the decimal point is <i>prec</i> + 5. For DMS (degree, minute, seconds) output, the number of digits after the decimal point in the seconds component is <i>prec</i> + 1. The minimum value of <i>prec</i> is 0 and the maximum is 10.</p>

<h1 id="ERRORS">ERRORS</h1>

<p>An illegal line of input will print an error message to standard output beginning with <code>ERROR:</code> and causes <b>GeodSolve</b> to return an exit code of 1. However, an error does not cause <b>GeodSolve</b> to terminate; following lines will be converted.</p>

<h1 id="ACCURACY">ACCURACY</h1>

<p>Using the (default) series solution, GeodSolve is accurate to about 15 nm (15 nanometers) for the WGS84 ellipsoid. The approximate maximum error (expressed as a distance) for an ellipsoid with the same equatorial radius as the WGS84 ellipsoid and different values of the flattening is</p>

<pre><code>   |f|     error
   0.01    25 nm
   0.02    30 nm
   0.05    10 um
   0.1    1.5 mm
   0.2    300 mm</code></pre>

<p>If <b>-E</b> is specified, GeodSolve is accurate to about 40 nm (40 nanometers) for the WGS84 ellipsoid. The approximate maximum error (expressed as a distance) for an ellipsoid with a quarter meridian of 10000 km and different values of the <i>a/b</i> = 1 - <i>f</i> is</p>

<pre><code>   1-f    error (nm)
   1/128   387
   1/64    345
   1/32    269
   1/16    210
   1/8     115
   1/4      69
   1/2      36
     1      15
     2      25
     4      96
     8     318
    16     985
    32    2352
    64    6008
   128   19024</code></pre>

<h1 id="MULTIPLE-SOLUTIONS">MULTIPLE SOLUTIONS</h1>

<p>The shortest distance returned for the inverse problem is (obviously) uniquely defined. However, in a few special cases there are multiple azimuths which yield the same shortest distance. Here is a catalog of those cases:</p>

<dl>

<dt id="lat1--lat2-with-neither-point-at-a-pole"><i>lat1</i> = -<i>lat2</i> (with neither point at a pole)</dt>
<dd>

<p>If <i>azi1</i> = <i>azi2</i>, the geodesic is unique. Otherwise there are two geodesics and the second one is obtained by setting [<i>azi1</i>,<i>azi2</i>] = [<i>azi2</i>,<i>azi1</i>], [<i>M12</i>,<i>M21</i>] = [<i>M21</i>,<i>M12</i>], <i>S12</i> = -<i>S12</i>. (This occurs when the longitude difference is near +/-180 for oblate ellipsoids.)</p>

</dd>
<dt id="lon2-lon1---180-with-neither-point-at-a-pole"><i>lon2</i> = <i>lon1</i> +/- 180 (with neither point at a pole)</dt>
<dd>

<p>If <i>azi1</i> = 0 or +/-180, the geodesic is unique. Otherwise there are two geodesics and the second one is obtained by setting [<i>azi1</i>,<i>azi2</i>] = [-<i>azi1</i>,-<i>azi2</i>], <i>S12</i> = -<i>S12</i>. (This occurs when <i>lat2</i> is near -<i>lat1</i> for prolate ellipsoids.)</p>

</dd>
<dt id="Points-1-and-2-at-opposite-poles">Points 1 and 2 at opposite poles</dt>
<dd>

<p>There are infinitely many geodesics which can be generated by setting [<i>azi1</i>,<i>azi2</i>] = [<i>azi1</i>,<i>azi2</i>] + [<i>d</i>,-<i>d</i>], for arbitrary <i>d</i>. (For spheres, this prescription applies when points 1 and 2 are antipodal.)</p>

</dd>
<dt id="s12-0-coincident-points"><i>s12</i> = 0 (coincident points)</dt>
<dd>

<p>There are infinitely many geodesics which can be generated by setting [<i>azi1</i>,<i>azi2</i>] = [<i>azi1</i>,<i>azi2</i>] + [<i>d</i>,<i>d</i>], for arbitrary <i>d</i>.</p>

</dd>
</dl>

<h1 id="EXAMPLES">EXAMPLES</h1>

<p>Route from JFK Airport to Singapore Changi Airport:</p>

<pre><code>   echo 40:38:23N 073:46:44W 01:21:33N 103:59:22E |
   GeodSolve -i -: -p 0

   003:18:29.9 177:29:09.2 15347628</code></pre>

<p>Equally spaced waypoints on the route:</p>

<pre><code>   for ((i = 0; i &lt;= 10; ++i)); do echo ${i}e-1; done |
   GeodSolve -I 40:38:23N 073:46:44W 01:21:33N 103:59:22E -F -: -p 0

   40:38:23.0N 073:46:44.0W 003:18:29.9
   54:24:51.3N 072:25:39.6W 004:18:44.1
   68:07:37.7N 069:40:42.9W 006:44:25.4
   81:38:00.4N 058:37:53.9W 017:28:52.7
   83:43:26.0N 080:37:16.9E 156:26:00.4
   70:20:29.2N 097:01:29.4E 172:31:56.4
   56:38:36.0N 100:14:47.6E 175:26:10.5
   42:52:37.1N 101:43:37.2E 176:34:28.6
   29:03:57.0N 102:39:34.8E 177:07:35.2
   15:13:18.6N 103:22:08.0E 177:23:44.7
   01:21:33.0N 103:59:22.0E 177:29:09.2</code></pre>

<h1 id="SEE-ALSO">SEE ALSO</h1>

<p>GeoConvert(1).</p>

<p>An online version of this utility is availbable at <a href="https://geographiclib.sourceforge.io/cgi-bin/GeodSolve">https://geographiclib.sourceforge.io/cgi-bin/GeodSolve</a>.</p>

<p>The algorithms are described in C. F. F. Karney, <i>Algorithms for geodesics</i>, J. Geodesy 87, 43-55 (2013); DOI: <a href="https://doi.org/10.1007/s00190-012-0578-z">https://doi.org/10.1007/s00190-012-0578-z</a>; addenda: <a href="https://geographiclib.sourceforge.io/geod-addenda.html">https://geographiclib.sourceforge.io/geod-addenda.html</a>.</p>

<p>The Wikipedia page, Geodesics on an ellipsoid, <a href="https://en.wikipedia.org/wiki/Geodesics_on_an_ellipsoid">https://en.wikipedia.org/wiki/Geodesics_on_an_ellipsoid</a>.</p>

<h1 id="AUTHOR">AUTHOR</h1>

<p><b>GeodSolve</b> was written by Charles Karney.</p>

<h1 id="HISTORY">HISTORY</h1>

<p><b>GeodSolve</b> was added to GeographicLib, <a href="https://geographiclib.sourceforge.io">https://geographiclib.sourceforge.io</a>, in 2009-03. Prior to version 1.30, it was called <b>Geod</b>. (The name was changed to avoid a conflict with the <b>geod</b> utility in <i>proj.4</i>.)</p>


</body>

</html>


